home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / DUNHAM.LS1 < prev    next >
Text File  |  1992-04-20  |  1KB  |  66 lines

  1. /* Listing #1: stackdump.c ... a program to dump the stack */
  2.  
  3. #define SPARC 1
  4. #define IBM 0
  5.  
  6. void fun1a();
  7. void fun1b();
  8. void fun2();
  9. void stackdump();
  10.  
  11. main()        /* call function fun1a or function fun1b */
  12. {
  13.   char text[16];
  14.   strcpy(text,"main text");
  15.   fun1a();
  16. }
  17.  
  18. void fun1a()
  19. {
  20.   char text[16];
  21.   strcpy(text,"fun1a text");
  22.   fun2();
  23. }
  24.  
  25. void fun1b()
  26. {
  27.   char text[16];
  28.   strcpy(text,"fun1b text");
  29.   fun2();
  30. }
  31.  
  32. void fun2()
  33. { int jj;
  34.   char text[16];
  35.   strcpy(text,"fun2 text");
  36. #if SPARC
  37.   printf("main address=%x\n",main);
  38.   printf("fun1a address=%x\n",fun1a);
  39.   printf("fun1b address=%x\n",fun1b);
  40.   printf("fun2 address=%x\n\n",fun2);
  41. #else if IBM
  42.   printf("main address=%x -> %x\n",main, *(unsigned long *)main);
  43.   printf("fun1a address=%x -> %x\n",fun1a, *(unsigned long *)fun1a);
  44.   printf("fun1b address=%x -> %x\n",fun1b, *(unsigned long *)fun1b);
  45.   printf("fun2 address=%x -> %x\n",fun2, *(unsigned long *)fun2);
  46. #endif
  47.   stackdump(&jj-32);   /* the 32 gives us the stack before variable jj */
  48. }
  49.  
  50. void stackdump(start)
  51. unsigned long start;
  52. {
  53.   int i,j;
  54.   for (i=0;i<128;i++)
  55.     {
  56.       printf("%08x ", (long)start);
  57.       printf("%08x ", *(unsigned long *)(start));
  58.       for (j=0;j<4;j++,start++)
  59.         printf("%c", isprint( *(unsigned char *)(start)) ?
  60.                           *(unsigned char *)(start) : ' ');
  61.       printf("\n");
  62.     }
  63. }
  64.  
  65.       
  66.